package com.chj.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @author Fuqiang Ma
 * 
 */
@Configuration
@EnableSwagger2
@PropertySources({ @PropertySource("classpath:swagger.properties") })
public class SwaggerConfig {

	@Value("${swagger.apiinfo.title}")
	private String title;

	@Value("${swagger.apiinfo.description}")
	private String description;

	@Value("${swagger.apiinfo.contact}")
	private String contact;

	@Value("${swagger.apiinfo.version}")
	private String version;

	@Value("${swagger.api.basePackage}")
	private String basePackage;

	@Value("${swagger.api.pathRegex}")
	private String pathRegex;

	@Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.regex(pathRegex)).build().apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title(title).description(description).contact(contact).version(version).build();
	}
}